#include<iostream>
#include<string>
#include<unistd.h>
#include<sys/types.h>
using namespace std;

//先描述
class Channel
{
public:
    Channel()
    {}
    ~Channel()
    {}
private:
    int _wfd;//写端
    string _name;
};
//提醒用户如何输入所需进程/管道数
void Usage(string proc)
{
    cout<<"Usage: "<< proc <<"process-num"<<endl;
}

//子进程任务/需要做什么
void Worker()
{}

//我们自己就是master
int main(int argc,char *argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        return 1;
    }
    int num = stoi(argv[1]);
    for(int i=0;i<num;i++)
    {
        //1.先有管道
        int pipefd[2] = {0};
        int n = pipe(pipefd);
        if(n < 0)
        {
            //创建管道失败
            return 2;
        }
        //2.创建指定个数的进程worker
        pid_t id = fork();
        if(id < 0)
        {
            return 3;
        }

        if(id == 0)
        {
            ::close(pipefd[1]);//子进程读read
            //child
            Worker();
            exit(0);
        }


        //父进程执行
        ::close(pipefd[0]);//父进程写 write
    }




    return 0;
}